package com.hyt.it.ogt.data.service.kw.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.hyt.core.base.BaseServiceImpl;
import com.hyt.it.ogt.data.mapper.kw.PushPjMapper;
import com.hyt.it.ogt.data.model.entity.kw.PushPj;
import com.hyt.it.ogt.data.service.kw.IPushPjService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liuqi
 * @date 2022-06-07
 */
@Service
public class PushPjServiceImpl extends BaseServiceImpl<PushPjMapper, PushPj> implements IPushPjService {

    @DS("kz")
    @Override
    public List<PushPj> getList() {
        return this.lambdaQuery().eq(PushPj::getStatus, 0).orderByAsc(PushPj::getId).list();
    }

    @DS("kz")
    @Override
    public List<PushPj> getListExcludeOfficeId(List<String> officeIdList) {
        if(!officeIdList.isEmpty()) {
            return this.lambdaQuery().eq(PushPj::getStatus, 0).notIn(PushPj::getOfficeId, officeIdList).orderByAsc(PushPj::getId).list();
        }else {
            return getList();
        }
    }

    @DS("kz")
    @Override
    public List<PushPj> getListByOfficeId(String officeId) {
        return this.lambdaQuery().eq(PushPj::getOfficeId, officeId).eq(PushPj::getStatus, 0).orderByAsc(PushPj::getId).list();
    }

    @DS("kz")
    @Override
    public List<PushPj> findListByOfficeIds(List<String> officeIds) {
        return this.lambdaQuery().in(PushPj::getOfficeId, officeIds).eq(PushPj::getStatus, 0).orderByAsc(PushPj::getId).list();
    }

    @DS("kz")
    @Override
    public void updateStatus(Long id, Integer status) {
        this.lambdaUpdate().eq(PushPj::getId, id).set(PushPj::getStatus, status).update();
    }

    @DS("kz")
    @Override
    public void updateStatus(Long id, Integer status, String error) {
        this.lambdaUpdate().eq(PushPj::getId, id).set(PushPj::getStatus, status).set(PushPj::getError, error).update();
    }

    @DS("kz")
    @Override
    public void delete(Long id) {
        this.lambdaUpdate().eq(PushPj::getId, id).remove();
    }

}
